package com.jinly.ryder.flow.web;

import com.jinly.ryder.common.auth.LoginContent;
import com.jinly.ryder.flow.service.FlowApplyAuditService;
import com.jinly.ryder.flow.service.model.FlowApply;
import com.jinly.ryder.flow.service.model.FlowAudit;
import com.jinly.ryder.flow.web.mapping.FlowApplyVOMapping;
import com.jinly.ryder.flow.web.mapping.FlowAuditVOMapping;
import com.jinly.ryder.flow.web.vo.FlowApplyVO;
import com.jinly.ryder.flow.web.vo.FlowAuditVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("flow/audit")
@RequiredArgsConstructor
public class FlowApplyAuditController {


    private final FlowApplyAuditService flowApplyAuditService;
    private final FlowApplyVOMapping flowApplyVOMapping;
    private final FlowAuditVOMapping flowAuditVOMapping;

    @PutMapping("cancelApply")
    public void cancelApply(Long applyId) {
        flowApplyAuditService.cancelApply(applyId, LoginContent.getUserId());
    }

    @PostMapping("submitApply")
    public void submitApply(@RequestBody FlowApplyVO flowApplyVO) {
        FlowApply flowApply = flowApplyVOMapping.toModel(flowApplyVO);
        flowApply.setApplyUserId(LoginContent.getUserId());
        log.info("submitApply:{}", flowApply);
        flowApplyAuditService.submitApply(flowApply);
    }


    @PostMapping("submitAudit")
    public void submitAudit(@RequestBody FlowAuditVO flowAuditVO) {
        FlowAudit flowAudit = flowAuditVOMapping.toModel(flowAuditVO);
        flowAudit.setAuditUserId(LoginContent.getUserId());
        log.info("submitAudit:{}", flowAudit);
        flowApplyAuditService.submitAudit(flowAudit);
    }
}
